home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / pcxpas.com / PCX256.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-10-15  |  3.7 KB  |  82 lines

  1. ;==============================
  2. ;Linkable module for PCX256.PAS
  3. ;==============================
  4.  
  5. data    segment word
  6.  
  7.         extrn   datalength: word
  8.         extrn   scratch: dword
  9.         extrn   page_addr: word
  10.         extrn   repeatcount: byte
  11.         extrn   video_index: word
  12.  
  13. data    ends
  14.  
  15. code segment word public
  16. assume cs:code, ds:data
  17.  
  18. public  decode_pcx256
  19.  
  20. ;=========================================================================
  21.  
  22. DECODE_PCX256    PROC    NEAR
  23.  
  24.                 mov     ax, page_addr               ;start of video buffer
  25.                 mov     es, ax                      ;put in es for addressing
  26.                 mov     bl, repeatcount             ;count in bl
  27.                 mov     si, word ptr 0              ;index into scratch
  28.                 mov     di, video_index             ;index into video
  29.                 xor     ch, ch                      ;clean up loop counter
  30.                 cld                                 ;clear DF
  31. ;-------------------------------------------------------------------------
  32. ;Read buffer and decode data
  33.  
  34. ;Here's how the data compression system works. Each byte is either image
  35. ;data or a count byte that tells how often the next image byte is repeated.
  36. ;The byte is image data if it follows a count byte, or if either of the top
  37. ;two bits is clear. Otherwise it is a count byte, with the count derived
  38. ;from the lower 6 bits.
  39.  
  40. getbyte:        cmp     si, datalength              ;end of scratch buffer?
  41.                 je      exit                        ;yes, quit
  42.                 push    es                          ;save video address
  43.                 push    di                          ;save video index
  44.                 les     di, scratch                 ;put pointer in es:di
  45.                 add     di, si                      ;add offset
  46.                 mov     al, [es:di]                 ;get byte from scratch
  47.                 inc     si                          ;increment index
  48.                 pop     di                          ;restore video index
  49.                 pop     es                          ;restore video address
  50.                 cmp     bl, 0                       ;was prev. byte a count?
  51.                 jg      repeats                     ;yes, this is data
  52.                 mov     ah, al                      ;no, copy byte to ah
  53.                 and     ah, 192                     ; and test high bytes
  54.                 cmp     ah, 192
  55.                 jne     is_data                     ;not set, not a count
  56. ;--------------------------------------------------------------------------
  57. ;It's a count byte
  58.                 xor     al, 192                     ;get count from 6 low bits
  59.                 mov     bl, al                      ;store repeat count
  60.                 jmp short  getbyte                  ;go get data byte
  61. ;----------------------------------------------------------------------------
  62. ;It's a single data byte
  63. is_data:        stosb                               ;byte into video
  64.                 jmp     getbyte
  65. ;---------------------------------------------------------------------------
  66. ;It's data to be written "count" times
  67. repeats:        mov     cl, bl                      ;set counter
  68.                 rep     stosb                       ;write byte cx times
  69.                 mov     bl, 0                       ;clear count byte
  70.                 jmp     getbyte
  71. ;-------------------------------------------------------------------------
  72. exit:           mov     video_index, di             ;save status for next
  73.                 mov     repeatcount, bl             ;  run thru buffer
  74.                 ret
  75.  
  76. DECODE_PCX256   endp
  77.  
  78. ;=========================================================================
  79. code ends
  80. end
  81.  
  82.